#!/bin/bash
gits_file=$HOME/Documents/gits
install_file=/usr/local/bin/
if [ ! -d $gits_file ];then
	mkdir -p $gits_file
else
    case $1 in
	install)
		sudo cp $0 $install_file
		sudo chmod +x $install_file/$0;;
	list)
		ls $gits_file;;
    	email)
        	git config --global user.email "$2";;
    	name)
        	git config --global user.name "$2";;
	remember)
		git config --global credential.helper store;;
    	clone)
        	cd $gits_file
        	git clone $2;;
    	pull)
        	cd $gits_file/"$2"
        	git pull;;
    	push)
        	cd $gits_file/"$2"
        	git add .
        	git commit -m "$HOSTNAME `date +"%Y-%m-%d %T"`"
        	git push;;
    	now)
        	git add .
        	git commit -m "$HOSTNAME `date +"%Y-%m-%d %T"`"
        	git push;;
    	*)
        	echo "格式：`basename $0` [选项] [参数]"
        	echo "  install		安装到指定位置"
        	echo "  list		查看gits仓库"
        	echo "  email		登陆邮箱"
        	echo "  name		登陆用户"
        	echo "  remember	下次输入账号密码时记住"
        	echo "  clone		克隆到本地仓库目录"
        	echo "  pull 		更新本地仓库"
        	echo "  push		上传本地仓库"
        	echo "  now		上传当前所在目录仓库"
        	echo "注意：本地仓库目录在$gits_file下，本地仓库不需要输入绝对路径";;
    esac
fi
